import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PostsVO, PostsForm, PostsQuery } from '@/api/posts/posts/types';

/**
 * 查询帖子列表
 * @param query
 * @returns {*}
 */

export const listPosts = (query?: PostsQuery): AxiosPromise<PostsVO[]> => {
  return request({
    url: '/posts/posts/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询帖子详细
 * @param postId
 */
export const getPosts = (postId: string | number): AxiosPromise<PostsVO> => {
  return request({
    url: '/posts/posts/' + postId,
    method: 'get'
  });
};

/**
 * 新增帖子
 * @param data
 */
export const addPosts = (data: PostsForm) => {
  return request({
    url: '/posts/posts',
    method: 'post',
    data: data
  });
};

/**
 * 修改帖子
 * @param data
 */
export const updatePosts = (data: PostsForm) => {
  return request({
    url: '/posts/posts',
    method: 'put',
    data: data
  });
};

/**
 * 删除帖子
 * @param postId
 */
export const delPosts = (postId: string | number | Array<string | number>) => {
  return request({
    url: '/posts/posts/' + postId,
    method: 'delete'
  });
};
